<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
	<head>
	 	<base href="<%=basePath%>">
		<meta charset="UTF-8">
		<title>小程序助手-我的小程序</title>
		<meta name="keywords" content="小程序助手,小程序商城,微信小程序,小程序">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<link href="static/miniApp/css/search.css" rel="stylesheet" />
		<link href="static/miniApp/css/index.css" rel="stylesheet" />
		<link href="static/miniApp/css/myapp.css" rel="stylesheet" />
		<script src="static/miniApp/js/jquery-1.7.1.min.js" type="text/javascript"></script>
	</head>
	<body>
		<%@ include file="header.jsp"%>
		<div class="center-content">
			<div class="center-content-up">
				<div class="center-head-portrait">
					<img src="uploadFiles/uploadImgs/userphoto/${miniappLoginApp.icon }" />
				</div>
				<div class="personage-info">
					<div class="center-username">你好，${miniappLoginApp.name }</div>
				</div>
				<button class="amend-info" id="amend-info">修改信息</button>
				<button class="logout-info" id="logout-info" onclick="window.location.href='miniapp/logout'">注销</button>
			</div>
			<div class="center-content-down">
				<div class="my-issue-title">
					我的发布
				</div>
				<div class="search-content">
					<div class="miniapp-list-content">
						<ul class="miniapp-list-content-ul clearfix js-miniapp-list">
					        <c:forEach items="${applist}" var="var" varStatus="vs">
							<li class="miniapp-item">
					        	<a class="miniapp__link" href="miniapp/jumpUpdProduct?updId=${var.ID }">
					        	<div class="miniapp-header">
						        	<img class="miniapp-header__app-icon" src="uploadFiles/uploadImgs/pc/${var.PROD_ICON }" />
						        	<div class="app-header-corp">
						        		<span class="app-header-corp__app-name">${var.PROD_NAME }</span> 
						        		<span class="app-header-corp__auth-name">
						        			<span class="app-header-corp__name-tip">作者:</span>
						        			 ${var.AUTHOR}
						        		</span>
						        	</div>
						        	
						        	<div class="divrr">
						        			<img class="erweima" src="uploadFiles/uploadImgs/pc/${var.QR_CODE_ICON }" />
						        		<span class="miniapp-header__app-try js-miniapp-header-try">扫码体验</span>
						        	
							        	<div class="hover-erweima">
							        		<img src="uploadFiles/uploadImgs/pc/${var.QR_CODE_ICON }" />
							        		<p>扫码体验</p>
							        	</div>
						        	</div>	
					        	</div>
					        	
					        	<div class="miniapp-header-tag">
								<c:choose>
									<c:when test="${fn:length(var.LABELS_ARR) <= 3}">
					        			<c:forEach items="${var.LABELS_ARR}" var="item" varStatus="vs">
					        				<span class="miniapp-tag-item">${item.LABLE_NAME }</span>
					        			</c:forEach>
									</c:when>
									<c:otherwise>
					        			<c:forEach items="${var.LABELS_ARR}" begin="0" end="2" var="item" varStatus="vs">
					        			<span class="miniapp-tag-item">${item.LABLE_NAME }</span>
					        			</c:forEach>
					        			 <i class="miniapp-tag-item-i"></i>
									</c:otherwise>
								</c:choose>
								</div>
								<div class="index-star-level">
									<c:choose>
										<c:when test="${var.STAR == '5'}">
												<span class="miniapp-tag-item red"></span>
												<span class="miniapp-tag-item red"></span>
												<span class="miniapp-tag-item red"></span>
												<span class="miniapp-tag-item red"></span>
												<span class="miniapp-tag-item red"></span>
										</c:when>
										<c:when test="${var.STAR == '4'}">
												<span class="miniapp-tag-item red"></span>
												<span class="miniapp-tag-item red"></span>
												<span class="miniapp-tag-item red"></span>
												<span class="miniapp-tag-item red"></span>
												<span class="miniapp-tag-item grey"></span>
										</c:when>
										<c:when test="${var.STAR == '3'}">
												<span class="miniapp-tag-item red"></span>
												<span class="miniapp-tag-item red"></span>
												<span class="miniapp-tag-item red"></span>
												<span class="miniapp-tag-item grey"></span>
												<span class="miniapp-tag-item grey"></span>
										</c:when>
										<c:when test="${var.STAR == '2'}">
												<span class="miniapp-tag-item red"></span>
												<span class="miniapp-tag-item red"></span>
												<span class="miniapp-tag-item grey"></span>
												<span class="miniapp-tag-item grey"></span>
												<span class="miniapp-tag-item grey"></span>
										</c:when>
										<c:when test="${var.STAR == '1'}">
												<span class="miniapp-tag-item red"></span>
												<span class="miniapp-tag-item grey"></span>
												<span class="miniapp-tag-item grey"></span>
												<span class="miniapp-tag-item grey"></span>
												<span class="miniapp-tag-item grey"></span>
										</c:when>
										<c:otherwise>
												<span class="miniapp-tag-item grey"></span>
												<span class="miniapp-tag-item grey"></span>
												<span class="miniapp-tag-item grey"></span>
												<span class="miniapp-tag-item grey"></span>
												<span class="miniapp-tag-item grey"></span>
										</c:otherwise>
									</c:choose>
								</div>
					        	</a>
					        </li>			
							</c:forEach>			
				    	</ul>
					</div>
				</div>
			</div>
		</div>
		
		<div class="center_view" id="amend-info-alert">
			<div class="center_login">
				<div class="center_login_nav">
					<ul>
						<!--<li class="click" id="login">登录</li>-->
						<li id="register">修改信息</li>
					</ul>
				</div>
				 <!--数据表-->
				<form action="miniapp/upduser" method="post" onsubmit="return checkInfo();" id="updUserInfoForm" enctype="multipart/form-data">
					<table cellspacing="0" style="width: 560px;margin:0 auto; border: 1px solid #EAEAEA;font-size: 12px;margin-top: 20px;">
						<tr onclick="clickImgPreview('5')">
							<td>头像</td>
							<td>
								<div class="input_pic">
									<img id="imgPreview5" class="pic" width="100%" height="100%" 
										src="uploadFiles/uploadImgs/userphoto/${miniappLoginApp.icon }" border="0" />
				                    <input type="file" class="hdnImg" name="icon" id="hdnImg5"  onchange="javascript:setImagePreview('5');">
								</div>
							</td>
							<td style="position: relative;">
							  	<lable class="HeadportraitX">修改头像</lable>
							</td>
						</tr>
						<tr>
							<td>账号</td>
							<td>
								${loginName }
								<input type="hidden" value="0" name="isupdpwd" id="isupdpwd"/>
							</td>
							<td><a class="modify-password-button">修改密码</a></td>
						</tr>
						<tr>
							<td>邮箱</td>
							<td><input class="center-email" type="text" value="${miniappLoginApp.email }" name="email" id="upd_email" /></td>
							<td></td>
						</tr>
						<tr>
							<td>昵称</td>
							<td><input class="center-nick" type="text" value="${miniappLoginApp.name }" name="name" id="upd_name"/></td>
							<td></td>
						</tr>
						<tr class="modify-password">
							<td>原密码</td>
							<td><input class="center-nick" type="password" name="odlpwd" id="upd_oldpwd"/></td>
							<td></td>
						</tr>
						<tr class="modify-password">
							<td>修改密码</td>
							<td><input class="center-nick" type="password" name="newpwd" id="upd_newpwd"/></td>
							<td></td>
						</tr>
						<tr class="modify-password">
							<td>确认修改</td>
							<td><input class="center-nick" type="password" name="surenewpwd" id="upd_surenewpwd" /></td>
							<td></td>
						</tr>
					</table>
				<button class="center_button">修改</button>
				<input type="button" class="center_quxiao" value="取消"/>
				</form>
			</div>
			<div class="center_view_bg"></div>
		</div>
		
		<%@ include file="footer.jsp"%>
	</body>
	
		<style>
			
		</style>
	<script type="text/javascript">
	$(".modify-password-button").click(function(){
		if($(".modify-password").css("display")=="none"){
			$(".modify-password").show();
			$("#isupdpwd").val('1');//修改密码
		}else{
			$(".modify-password").hide();
			$("#isupdpwd").val('0');//不修改密码
		}
	});
	$("#amend-info").click(function(){
		if($("#amend-info-alert").css("display")=="none"){
			$("#amend-info-alert").show();
		}else{
			$("#amend-info-alert").hide();
		}
	});
	
	$(".center_view_bg,.center_quxiao").click(function(){
		$("#amend-info-alert").hide();
	});
	
	function checkInfo(){
		var email = $("#upd_email").val();
		if(email == null || email == undefined || email == ""){
			alert("请输入邮箱.");
			$("#email").focus();
			return false;
		}
		var name = $("#upd_name").val();
		if(name == null || name == undefined || name == ""){
			alert("请输入昵称.");
			$("#name").focus();
			return false;
		}
		var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
		if(!myreg.test(email)){
			alert("请输入有效的邮箱.");
			$("#email").focus();
			return false;
		}
		var isupdpwd = $("#isupdpwd").val();
		//确认是否修改密码
		if(isupdpwd == '1'){
			var oldpwd = $("#upd_oldpwd").val();
			if(oldpwd == null || oldpwd == undefined || oldpwd == ""){
				alert("请输入原密码.");
				return false;
			}
			var newpwd = $("#upd_newpwd").val();
			if(newpwd == null || newpwd == undefined || newpwd == ""){
				alert("请输入新密码.");
				return false;
			}
			var surenewpwd = $("#upd_surenewpwd").val();
			if(surenewpwd == null || surenewpwd == undefined || surenewpwd == ""){
				alert("请输入密码确认.");
				return false;
			}
			if(newpwd != surenewpwd){
				alert("两次密码输入不一致.");
				return false;
			}
			var checkPwdCode = "";
			//检验密码是否正确
			$.ajax({
				type: "POST",
				async: false,
				url: 'miniapp/checkpwd.do?pwd=' + oldpwd,
				dataType:'json',
				success: function(data){
					checkPwdCode = data.code;
				}
			});
			if(checkPwdCode != "1"){
				alert("原密码错误.");
				return false;
			}
		}
		var emailNum = "";
		//检验名称是否存在
		$.ajax({
			type: "POST",
			async: false,
			url: 'miniapp/checkEmail.do?email=' + email,
			dataType:'json',
			success: function(data){
				emailNum = data.emailNum;
			}
		});
		if(emailNum == "" || emailNum == undefined || emailNum == null || parseInt(emailNum) != 0){
			alert("邮箱已存在.");
			return false;
		}
		return true;
	}
	
	function clickImgPreview(index){
		document.getElementById("hdnImg" + index).click();
	}

	$(function(){
//		头像选择框的监听事件
	    $(".Headportrait").change(function(){
	    	var val = $(".Headportrait").val();
	    	$(".pic").attr("src",val);
	    }) ;
	    $("span").click(function(){
	            var m = $(this).parent().prev().find("span");
	            var n = $(this).parent().prev().find("input");
	            if($(m).css("display") == 'block'){
	            	$(n).val(m.text());
	            	$(this).text("取消修改");
	            	$(m).css("display","none");
	            	$(n).css("display","block");
	            	
	                $(n).focus();
	            }else{
	            	$(n).val("");
	        		$(this).text("修改"+$(this).parent().prev().prev().text()); 
	            	$(m).css("display","block");
	            	$(n).css("display","none");
	            }         
	        $(".submit").click(function(){
	        	for(var i = 0 ; i < $(".first").length; i++){
	        		$(".pointer").eq(i).text("修改"+$('.first').eq(i).text()); 
	        	}
	        	if(n.val() == ""){
	        	}else{
	        		m.text(n.val());        	
	        	    $(m).css("display","block");
	                $(n).css("display","none");
	           }
	        });
	    });	
	});
	</script>
</html>
